package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

import model.*;
import util.ConnectDataBase;

public class CustomerDAO  {
	Vector listcustomer;
	ConnectDataBase connectDataBase;

	public CustomerDAO() {
		connectDataBase= new ConnectDataBase();
		listcustomer = new Vector();
	}

	public Vector getListcustomer() {
		try {
			ResultSet rs = connectDataBase
					.query_select("Select * from Customer");
			while (rs.next()) {

				int customer_id = Integer.parseInt(rs.getString("customer_id"));
				String numberid = rs.getString("numberid");
				String firstname = rs.getString("firstname");
				String lasttname = rs.getString("lasttname");
				String address = rs.getString("address");
				String phonenumber = rs.getString("phonenumber");
				String creditcard = rs.getString("creditcard");

				Customer cus = new Customer(customer_id, numberid, firstname,
						lasttname, address, phonenumber, creditcard);
				listcustomer.add(cus);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return listcustomer;
	}

	
	public void insert_Customer(Customer cus) {
		
		String sql = "Insert into Customer values(" + cus.getCustomer_id()
				+ "," + cus.getNumberid() + ",'" + cus.getFirstname() + "','"
				+ cus.getLasttname() + "','" + cus.getAddress() + "',"
				+ cus.getPhonenumber() + "," +cus.getCreditcard()+ ")";
		 connectDataBase.query_update(sql);
	}
	
	public void delete_Customer(Customer cus) {
		String sql = "Delete from Customer where customer_id="
				+ cus.getCustomer_id();
		connectDataBase.query_update(sql);
	}

	
}
